import EventCenter from "../../TFrame/script/helper/EventCenter";
import EventNames from "../EventNames";
import PlayerDataMgr from "../PlayerDataMgr";

const { ccclass, property, requireComponent } = cc._decorator;

@ccclass
@requireComponent(cc.Label)
export default class TipLabel extends cc.Component {

    @property
    isSelectScene = false;

    @property(cc.AudioClip)
    tipAddAudio:cc.AudioClip = null;

    thisLabel: cc.Label = null;

    onLoad() { 
        this.thisLabel = this.node.getComponent(cc.Label);
        this.updateText();

        EventCenter.on(EventNames.TipChangedADD, () => {
            this.updateText();
            this.tipAddAudio && cc.audioEngine.playEffect(this.tipAddAudio, false)
        }, this)

        
        EventCenter.on(EventNames.TipChangedDec, () => {
            this.updateText();
        }, this)
    }
    
    blink() {

    }

    private getText() {
        // if(PlayerDataMgr.getInstance().tipsOwned <= 0 && this.isSelectScene == false)
        //     return "AD";
        // return 'x' + PlayerDataMgr.getInstance().tipsOwned.toString();
        return "AD"
    }

    private updateText() {
        this.thisLabel.string = this.getText();
        this.thisLabel.node.stopAllActions()
        this.thisLabel.node.opacity = 255;
        this.thisLabel.node.runAction(cc.blink(2, 4));
    }
}
